﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace VIA.Integration
{
    //public interface ISuportClearAlarm
    //{
    //    void ClearAlarm();
    //}

    public static class AxisExtensions
    {

        public static async Task MoveToAsync(this IEnumerable<IAxis> axies,string id,CancellationToken cancellationToken)
        {
            await Parallel.ForEachAsync(axies, cancellationToken, async (x, t) => await x.MoveToAsync(id, t));
        }
        public static double GetTargetPosition(this IAxis axis, string id)
        {
            var path = axis.MotionPaths.FirstOrDefault(x => x.Id == id);
            if (path != null)
                return path.Target;
            else
                throw new Exception($"在轴[{axis.Name}]中未找到名为[{id}]的路径");
        }
        public static double GetTargetSpeed(this IAxis axis, string id)
        {
            var path = axis.MotionPaths.FirstOrDefault(x => x.Id == id);
            if (path != null)
                return path.VelocityCurve.Maxvel;
            else
                throw new Exception($"在轴[{axis.Name}]中未找到名为[{id}]的速度参数");
        }
        public static VelocityCurve GetVelocityCurve(this IAxis axis, string id)
        {
            var path = axis.MotionPaths.FirstOrDefault(x => x.Id == id);
            if (path != null)
                return path.VelocityCurve;
            else
                throw new Exception($"在轴[{axis.Name}]中未找到名为[{id}]的参数");
        }
    }

}
